﻿using System.IO.Compression;

namespace Basic.Base.Compress.Impl;

internal class BrotliCompression : IBasicCompression
{
    public MemoryStream Compress(MemoryStream inputStream)
    {
        MemoryStream outputStream = new MemoryStream();
        using BrotliStream handlerStream = new BrotliStream(outputStream, CompressionMode.Compress);
        inputStream.CopyTo(handlerStream);

        return outputStream;
    }

    public byte[] Compress(byte[] inputData)
    {
        using MemoryStream inputStream = new MemoryStream(inputData);
        using MemoryStream outputStream = Compress(inputStream);
        return outputStream.ToArray();
    }

    public MemoryStream Decompress(MemoryStream inputStream)
    {
        using BrotliStream handlerStream = new BrotliStream(inputStream, CompressionMode.Decompress);
        MemoryStream outputStream = new MemoryStream();
        handlerStream.CopyTo(outputStream);

        return outputStream;
    }

    public byte[] Decompress(byte[] inputData)
    {
        using MemoryStream inputStream = new MemoryStream(inputData);
        using MemoryStream outputStream = Decompress(inputStream);
        return outputStream.ToArray();
    }

}